package com.qianji.controller;

import com.qianji.api.IntegralApps;
import com.qianji.service.IntegralService;
import com.qianji.utils.Result;
import com.qianji.vo.IntegralAddVO;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by 阳家桂 on 2021/3/12 15:43
 * 积分
 */
@RestController
@Slf4j
@RequestMapping("/integral/")
public class IntegralController {
    @Autowired
    private IntegralService integralService;

    /**
     * 新增积分
     * @param integralAddVO
     * @return
     */
    @ApiOperation("增加")
    @RequestMapping(value = "add",method = RequestMethod.POST)
    public Result addIntegral(@RequestBody IntegralAddVO integralAddVO){
        Integer result = integralService.addIntegral(integralAddVO);
        if (result>0){
            return Result.success("添加成功",200);
        }else {
            return  Result.failed("添加失败",400);
        }
    }

    /**
     * 积分消费/失效
     * @param id
     * @return
     */
    @ApiOperation("删除")
    @RequestMapping(value = "delete",method = RequestMethod.POST)
    public Result deleteCon(String id){

        Integer result = integralService.deleteIntegral(id);
        if (result>0){
            return Result.success("删除成功",200);
        }else {
            return  Result.failed("删除失败",400);
        }
    }

}
